package com.level2app.ui.home;

import android.app.Activity;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.level2app.R;
import com.level2app.base.BaseActivity;
import com.level2app.databinding.ActivityCategoriesListBinding;
import com.level2app.ui.home.view.CategoriesListViewModel;
import com.level2app.ui.search.SearchActivity;
import com.level2app.ui.search.SearchAddressActivity;
import com.level2app.utils.FragmentUtils;
import com.level2app.utils.JumpIntent;
import com.level2app.utils.ToastHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * 分类列表
 */
public class CategoriesListActivity extends BaseActivity<ActivityCategoriesListBinding, CategoriesListViewModel> {
    private final List<Fragment> mFragments = new ArrayList<>();
    private int currentItem = 0;

    @Override
    protected CategoriesListViewModel bindModel() {
        return getViewModel(this, CategoriesListViewModel.class);
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void initData() {
        String title = getIntent().getStringExtra("title");
        binding.titleTv.setText(title);
        //设置位置城市
        binding.includeLayout.cityNameTv.setText("Miami");
        //通知消息数量
        binding.includeLayout.notifyNumTv.setText("8");
        binding.includeLayout.logoIv.setVisibility(View.GONE);
//        mFragments.add(CategoriesListFragment.newInstance(0));
        mFragments.add(CategoriesListFragment.newInstance(1));
//        binding.vp.addOnPageChangeListener(mPageChangeListener);
//        MyFragmentPagerAdapter mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), 1, mFragments);
//        binding.vp.setAdapter(mAdapter);
        FragmentUtils.add(getSupportFragmentManager(), mFragments, R.id.categoriesFl, 0);
    }

    @Override
    protected void initClick() {
        super.initClick();
        viewModel.onDelayClick(binding.includeLayout.locationLl, o -> {
            //定位
            JumpIntent.jump(this, SearchAddressActivity.class);
        });
        viewModel.onDelayClick(binding.includeLayout.searchIv, o -> {
            //搜索
            JumpIntent.jump(this, SearchActivity.class);
        });
        viewModel.onDelayClick(binding.includeLayout.notifyIv, o -> {
            //通知
            JumpIntent.jump(this, NotificationsActivity.class);
        });
//        viewModel.onDelayClick(binding.offerTv, o -> {
//            if (currentItem != 0) {
//                currentItem = 0;
//                binding.vp.setCurrentItem(currentItem);
//            }
//        });
//        viewModel.onDelayClick(binding.campaignsTv, o -> {
//            if (currentItem != 1) {
//                currentItem = 1;
//                binding.vp.setCurrentItem(currentItem);
//            }
//        });
        viewModel.onDelayClick(binding.backIv, o -> {
            finish();
        });
    }

//    private final ViewPager.OnPageChangeListener mPageChangeListener = new ViewPager.OnPageChangeListener() {
//        @Override
//        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//        }
//
//        @Override
//        public void onPageSelected(int position) {
//            currentItem = position;
//            if (position == 0) {
//                binding.campaignsTv.setBackground(null);
//                binding.campaignsTv.setTextColor(ContextCompat.getColor(CategoriesListActivity.this, R.color.color_8d98af));
//                binding.campaignsTv.setTypeface(null, Typeface.NORMAL);
//                binding.offerTv.setBackgroundResource(R.drawable.shape_e9eded_32dp);
//                binding.offerTv.setTextColor(ContextCompat.getColor(CategoriesListActivity.this, R.color.color_1e1e1e));
//                binding.offerTv.setTypeface(null, Typeface.BOLD);
//            } else {
//                binding.offerTv.setBackground(null);
//                binding.offerTv.setTextColor(ContextCompat.getColor(CategoriesListActivity.this, R.color.color_8d98af));
//                binding.offerTv.setTypeface(null, Typeface.NORMAL);
//                binding.campaignsTv.setBackgroundResource(R.drawable.shape_e9eded_32dp);
//                binding.campaignsTv.setTextColor(ContextCompat.getColor(CategoriesListActivity.this, R.color.color_1e1e1e));
//                binding.campaignsTv.setTypeface(null, Typeface.BOLD);
//            }
//        }
//
//        @Override
//        public void onPageScrollStateChanged(int state) {
//
//        }
//    };
}